<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>操作符</title>
</head>

<body>
  <script>
    // 前缀++/--
    let age = 29;
    let anotherAge = --age + 2;
    console.log(age); //28
    console.log(anotherAge); //30
    //后缀++/--
    let num1 = 2;
    let num2 = 20;
    let num3 = num1-- + num2;
    let num4 = num1 + num2;
    console.log(num3);//22
    console.log(num4);//21

    let s1 = "2";
    let s2 = "z";
    let b = false;
    let f = 1.1;
    let o = {
      valueOf() {
        return -1;
      }
    }
    console.log(s1++);//2,值已经变成了3.
    console.log(s2++);//NaN;
    console.log(b++);//0,值已经变成了1.
    console.log(--f);//0.10000000000000009,浮点值不精确.
    console.log(--o);//-2

    //一元加减
    let n = 25;
    n = +n;
    console.log(n);//25

    let s3 = "01";
    let s4 = "1.1";
    let s5 = "z";
    let t = true;
    let f1 = 1.1;
    let o1 = {
      valueOf() {
        return -1;
      }
    }
    // 一元加把其他类型的值全部转为数值.
    s3 = +s3;
    console.log(s3);//1
    s4 = +s4;
    console.log(s4);//1.1
    s5 = +s5;
    console.log(s5);//NaN
    t = +t;
    console.log(t);//1
    f1 = +f1;
    console.log(f1);//1.1
    o1 = +o1;
    console.log(o1);//-1

    let num5 = -18;
    console.log(num5.toString(2));//-10010
    //按位非
    let num6 = 25;
    let num7 = ~num6;
    console.log(num7);//-26(按位非操作符,取反再减一)
    //按位与
    let res = 25 & 3;
    console.log(res);//1
    //按位或
    let res1 = 25 | 3;
    console.log(res1);//27
    //按位异或
    let res2 = 25 ^ 3;
    console.log(res2);//26
    //左移
    let oldValue = 2;
    let newValue = oldValue << 5;
    console.log(newValue);//64
    //有符号右移
    let oldValue1 = 64;
    let newValue1 = oldValue1 >> 5;
    console.log(newValue1);//2
    //无符号右移
    let oldValue2 = 64;
    let newValue2 = oldValue2 >>> 5;
    console.log(newValue2);//2
    let oldValue3 = -64;
    let newValue3 = oldValue3 >>> 5;
    console.log(newValue3);//134217726
    //逻辑非! 使用两个叹号的结果与使用转型函数Boolean()结果一样.
    console.log(!!"blue");//true
    console.log(!!0);//false
    console.log(!!NaN);//false
    console.log(!!undefined);//false
    console.log(!!12345);//true
    //短路与&&
    let found = false;
    let res3 = (found && Undeclared);//改为true会报错.
    console.log(res3)
    //短路或||
    let found1 = true;
    let res4 = (found1 || Undeclared);//改为false会报错
    console.log(res4);
    //指数操作符
    console.log(Math.pow(2, 3));//8
    console.log(2 ** 3);//8
    let line = 3;
    line **= 2;
    console.log(line);//9
    //关系操作符
    let result = 'Black' < 'alphanet';
    console.log(result);//true,B的编码66,a的编码是97.
    let res5 = '23' < '3';//
    console.log(res5);//true,比较第一位字符编码.
    let res6 = '23' < 3;
    console.log(res6);//false
    // 全等
    console.log('55' == 55);//true
    console.log('55' === 55);//false
    //逗号
    let nu = 1, nu2 = 2, nu3 = 3;
    let n1 = (1, 2, 3, 4, 5);
    console.log(n1);//5
  </script>
</body>

</html>